package com.example.wxapi;

import android.os.Bundle;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.tencent.mm.opensdk.modelbase.BaseReq;
import com.tencent.mm.opensdk.modelbase.BaseResp;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
import com.example.util.Constant;

/**
 *
 */
public class WXPayActivity extends AppCompatActivity implements IWXAPIEventHandler {
    private IWXAPI api;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        api = WXAPIFactory.createWXAPI(this, Constant.WECHAT_APP_ID);
    }

    @Override
    public void onReq(BaseReq baseReq) {

    }

    @Override
    public void onResp(BaseResp baseResp) {
        switch (baseResp.errCode){
            case 0:
                Toast.makeText(WXPayActivity.this,"支付成功",Toast.LENGTH_SHORT).show();
                break;
            case -1:
                Toast.makeText(WXPayActivity.this,"支付失败",Toast.LENGTH_SHORT).show();
                break;
            case -2:
                Toast.makeText(WXPayActivity.this,"您已经取消支付",Toast.LENGTH_SHORT).show();
                break;
        }
        finish();
    }
}
